package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;


/**
 * The interface Order mapper.
 */
@Mapper
public interface OrderMapper {


    /**
     * 插入订单数据
     *
     * @param order the order
     */
    void insert(Orders order);

    /**
     * 分页条件查询并按下单时间排序
     *
     * @param ordersPageQueryDTO the orders page query dto
     * @return the page
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);


    /**
     * 根据id查询订单
     *
     * @param id the id
     * @return the by id
     */
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);


    /**
     * 根据id更新订单
     *
     * @param orders the orders
     */
    void update(Orders orders);

    /**
     * Select status integer.
     *
     * @param status the status
     * @return the integer
     */
    @Select("select count(*) from orders where status = #{status}")
    Integer selectStatus(Integer status);

    /**
     * 根据订单状态和下单时间查询订单
     *
     * @param status the status
     * @param time   the time
     * @return the by status and order time lt
     */
    @Select("select * from orders where status = #{status} and order_time < #{time} ")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime time);

    /**
     * Select one orders.
     *
     * @param ordersQuery the orders query
     * @return the orders
     */
    Orders selectOne(Orders ordersQuery);

    /**
     * 根据动态条件统计营业额
     *
     * @param map the map
     * @return the double
     */
    Double sumByMap(Map map);


    /**
     * 根据动态条件查询订单数据
     *
     * @param map the map
     * @return the integer
     */
    Integer countByMap(Map map);

    /**
     * 统计指定时间区域内的销量前十
     *
     * @param begin the begin
     * @param end   the end
     * @return the sales top
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
}
